package com.eurasia.assignment.controller.dto;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import com.eurasia.assignment.domain.Class;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

/**
 * 班级响应DTO
 * 用于向客户端返回班级信息
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ClassResponse {
    private Long id;
    private String className;
    private String grade;
    private String major;
    private String tutor;
    private Integer studentCount;
    private String createTime;
    private String remark;
    
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    
    /**
     * 将领域对象转换为响应DTO
     */
    public static ClassResponse fromDomain(Class classObj) {
        ClassResponse response = new ClassResponse();
        response.setId(classObj.getId());
        response.setClassName(classObj.getClassName());
        response.setGrade(classObj.getGrade());
        response.setMajor(classObj.getMajor());
        response.setTutor(classObj.getTutor());
        response.setStudentCount(classObj.getStudentCount());
        
        // 格式化创建时间
        if (classObj.getCreateTime() != null) {
            response.setCreateTime(classObj.getCreateTime().format(FORMATTER));
        }
        
        response.setRemark(classObj.getRemark());
        
        return response;
    }
} 